package com.kk.xhr.admin.controller.vo;

import com.kk.xhr.common.pojo.UserStatusEnum;
import com.kk.xhr.model.entity.User;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Set;

/**
 * 用户信息
 *
 * @author liujingcheng
 * @version 1.0, 2020/4/2 15:52
 * @since 1.0.0
 */
@ApiModel
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class UserVO {
    @ApiModelProperty(value = "用户id", example = "100010")
    private Long id;
    @ApiModelProperty(value = "名称", example = "shadow123")
    private String name;
    @ApiModelProperty(value = "用户名", example = "shadow123")
    private String username;
    @ApiModelProperty(value = "头像", example = "/s3/download/111xad1.jpg")
    private String avatar;
    @ApiModelProperty(value = "邮箱", example = "123@456.com")
    private String email;
    @ApiModelProperty(value = "手机号", example = "13567890123")
    private String phone;
    @ApiModelProperty(value = "办公电话", example = "25678889")
    private String telephone;
    @ApiModelProperty(value = "个性签名", example = "我就是我，颜色不一样的烟火~")
    private String introduction;
    @ApiModelProperty(value = "工号", example = "1010001")
    private Long workId;
    @ApiModelProperty(value = "工龄", example = "1")
    private Integer workAge;
    @ApiModelProperty(value = "部门", example = "后端开发部")
    private String department;
    @ApiModelProperty(value = "上级", example = "老李")
    private String boss;
    @ApiModelProperty(value = "职位", example = "java开发工程师")
    private String position;
    @ApiModelProperty(value = "等级", example = "p7")
    private String level;
    @ApiModelProperty(value = "状态", example = "ACTIVE")
    private UserStatusEnum status;
    @ApiModelProperty(value = "角色名")
    private Set<String> roles;
    @ApiModelProperty(value = "角色ids")
    private Set<Long> roleIds;

    public static UserVO from(User user) {
        return UserVO.builder()
            .id(user.getId())
            .name(user.getName())
            .username(user.getUsername())
            .avatar(user.getAvatarUrl())
            .email(user.getEmail())
            .phone(user.getPhone())
            .telephone(user.getTelephone())
            .introduction(user.getRemark())
            .workId(user.getWorkId())
            .workAge(user.getWorkAge())
            .status(UserStatusEnum.from(user.getStatus()))
            .build();
    }
}
